/* ==================================================================   
 * Created 2013-10-28下午:58:48 by 郑伟
 * ==================================================================  
 *  EMV  Level2
 * Copyright (c) SZZCS S&T Co.ltd ShenZhen, 2012-2013 
 * ================================================================== 
 * 深圳市中磁计算机技术有限公司拥有该文件的使用、复制、修改和分发的许可权
 * 如果你想得到更多信息，请访问 <http://www.szzcs.com/cn>
 *
 * SZZCS S&T Co.ltd ShenZhen owns permission to use, copy, modify and 
 * distribute this documentation.
 * For more information on EMV, please 
 * see <http://www.szzcs.com/cn>.  
 * ================================================================== 
 */
package com.hangup.activity;

import java.util.ArrayList;

import com.hangup.pojo.Post;
import com.hangup.pojo.Student;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class PublicApplication extends Application {
	private boolean login_flag;// 判断是否登录
	private Student stu;// 学生信息
	private String cityName;// 设置城市名称
	private int post_index;// 帖子下标
	private ArrayList<Post> post_;// 缓存帖子
	private ArrayList<Student> stus_;// 缓存学生

	private final static String TAG = "PublicApplication";
	private SharedPreferences _preferences = null;// 共享参数保存草稿
	private String POST_THEME = "post_theme";
	private String POST_TEXT = "post_text";
	private int stu_id;

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		login_flag = false;
		stu = new Student();
		cityName = "杭州";
		post_ = new ArrayList<Post>();
		post_index = 0;
		_preferences = getSharedPreferences(TAG, Context.MODE_PRIVATE);
	}

	@Override
	public void onTerminate() {
		// TODO Auto-generated method stub
		login_flag = false;
		stu = null;
		_preferences = null;
	}

	public boolean isLogin_flag() {
		return login_flag;
	}

	public void setLogin_flag(boolean login_flag) {
		this.login_flag = login_flag;
	}

	public Student getStu() {
		return stu;
	}

	public void setStu(Student stu) {
		this.stu = stu;
	}

	public String getCityName() {
		return cityName;
	}

	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

	public int getPost_index() {
		return post_index;
	}

	public void setPost_index(int post_index) {
		this.post_index = post_index;
	}

	public ArrayList<Post> getPost_() {
		return post_;
	}

	public void setPost_(ArrayList<Post> post_) {
		this.post_ = post_;
	}

	public ArrayList<Student> getStus_() {
		return stus_;
	}

	public void setStus_(ArrayList<Student> stus_) {
		this.stus_ = stus_;
	}

	public String getPost_theme() {
		return _preferences.getString(POST_THEME, null);
	}

	public String getPost_text() {
		return _preferences.getString(POST_TEXT, null);
	}

	public int getStu_id() {
		return _preferences.getInt("stu_id", -1);
	}

	public void savePostDraft(int stu_id, String theme, String text) {
		Editor editor = _preferences.edit();
		editor.putString(POST_THEME, theme);
		editor.putString(POST_TEXT, text);
		editor.putInt("stu_id", stu_id);
		editor.commit();
	}
}
